<template>
  <div>
    <el-table v-loading="loading" :data="dataSource" @row-click="handleRowClick" :height="autoHeight">
      <el-table-column prop="caseName" label="名称" align="center" show-overflow-tooltip>
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="90px">
        <div slot="header">
          <el-button type="primary" @click="$emit('edit', {} )" icon="el-icon-circle-plus-outline"></el-button>
        </div>
        <div slot-scope="scope">
          <el-button type="success" icon="el-icon-edit" circle @click="() => { $emit('edit', scope.row )}" title="编辑"></el-button>
          <el-button type="danger" icon="el-icon-delete" circle @click="removeData(scope.row, scope.$index)" title="删除"></el-button>
        </div>
      </el-table-column>
    </el-table>
    <div class="lab-table-page">
      <div style="display: inline-flex">
        <el-pagination
            :disabled="loading"
            :current-page="pageInfo.page"
            :page-sizes="[5, 10, 15, 20, 50, 100]"
            :page-size="pageInfo.pageSize"
            layout="total, sizes"
            :total="pageInfo.total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        />
        <el-button-group style="padding: 2px 5px">
          <el-button icon="el-icon-refresh" title="刷新" :disabled="loading" @click="loadSource([])" />
        </el-button-group>
      </div>
    </div>
  </div>
</template>

<script>
import IdeaTable from "@/mixins/IdeaTable";

export default {
  name: "MethodCaseTable",
  mixins: [IdeaTable],
  inject: {
    methodInfo: {
      from: 'methodInfo',
      default: function () {
        return { methodId: '0' }
      }
    }
  },
  computed:{
    autoHeight() {
      return `calc(100vh - 290px)`
    }
  },
  created() {
    this.queryUrl = '/methodCase/queryPage'
    this.saveUrl = '/methodCase/save'
    this.removeUrl = '/methodCase/delete/'
    this.rowKey = 'caseId'
    this.addFilter({ field: 'methodId', op: '=', value: this.methodInfo.methodId })
    this.pageInfo.sorts.push({ field: 'updateAt', asc: false })
    this.loadSource()
  },
  methods: {
    initEntity(){
      this.entityInfo = { dataState: 0 }
    }
  }
}
</script>

<style scoped>

</style>
